//
//  NSString+Extension.m
//  正则表达式
//
//  Created by J on 15/12/24.
//  Copyright © 2015年 J. All rights reserved.
//

#import "NSString+Extension.h"

@implementation NSString (Extension)
- (BOOL)match:(NSString*)pattern{
//    NSString* pattern = @"^[1-9]\\d{4,10}$";// 数字开头 数字结尾 中间 随意个 0 - 9 a - z A - Z .代表任意
    NSRegularExpression  *regex = [[NSRegularExpression alloc]initWithPattern:pattern options:0 error:nil];
    //2. 测试字符串
    NSArray* result = [regex matchesInString:self options:0 range:NSMakeRange(0, self.length)];
    //    NSLog(@"文字长度: %zd 匹配结
    return  result.count;
    
}

- (BOOL)isQQ{
    //5-11
    
    //1.不能以0开头
    //2.全部是数字
    //3.5-11位
    return [self match:@"^[1-9]\\d{4,10}$"];
 
}
- (BOOL)isPhoneNumber{
    
    //1.全部是数字
    //2.11位
    //3.13\15\18\17开头

    return [self match:@"^1[3,57,89]\\d{9}$"];
}

- (BOOL)isIPAddress{
    
    //1-3个数字: 0-255
    //
    return [self match:@"^192\\.168\\.\\d{1,3}.\\d{1,3}$"];
    
}
@end
